<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title></title>
		<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
		<!-- 引用Vue -->
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
		<!-- 引入组件库 -->
		<script src="https://unpkg.com/element-ui/lib/index.js"></script>
		<script type="text/javascript" src="../js/axios.js"></script>
		<script type="text/javascript" src="../js/qs.js"></script>
		<style>
			* {
				margin: 0;
				padding: 0;
			}
			
			.app {
				width: 750px;
				height: 500px;
				margin: 0 auto;
			}
			
			.border-t-a {
				margin-bottom: 20px;
			}
		</style>
	</head>

	<body>

		<div id="app" class="app">

			<hr class="border-t-a">

			<el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-form">

				<el-form-item label="投诉主题：" prop="theme">
					<el-input v-model="form.theme"></el-input>
				</el-form-item>

				<el-form-item label="客户：">
					<el-col :span="12">
						<el-form-item prop="custname">
							<el-input v-model="form.custname" disabled></el-input>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="投诉人:" prop="linkman">
							<el-select v-model="form.linkman" placeholder="请选择" @change="handleSelect1">
								<el-option v-for="item in customertoman" :key="item.linId" :label="item.linName" :value="item.linId">
								</el-option>
							</el-select>

						</el-form-item>
					</el-col>
				</el-form-item>

				<el-form-item>
					<el-col :span="8">
						<el-autocomplete class="inline-input" v-model="form.custname" :fetch-suggestions="querySearch" placeholder="请输入客户名字" :trigger-on-focus="false" @select="handleSelect">
							<template slot-scope="{ item }">
								<div class="name">{{ item.cus_name }}({{ item.cus_company }})</div>
							</template>
						</el-autocomplete>
					</el-col>
					<el-col class="line" :span="3" :offset="5">执行人：</el-col>
					<el-col :span="8">
						${username}
					</el-col>
				</el-form-item>

				<el-form-item label="时间：">
					<el-col :span="12">
						<el-form-item prop="date1">
							<el-date-picker type="date" placeholder="选择日期" v-model="form.date1" format="yyyy-MM-dd" value-format="yyyy-MM-dd" :picker-options="pickerOptions1"></el-date-picker>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="类型：" prop="type">
							<el-select v-model="form.type" placeholder="请选择类型">
								<el-option :key="423" label="产品投诉" :value="423"></el-option>
								<el-option :key="420" label="服务投诉" :value="420"></el-option>
								<el-option :key="421" label="意见投诉" :value="421"></el-option>
								<el-option :key="422" label="其它投诉" :value="422"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-form-item>

				<el-form-item label="紧急程度:" prop="degree">
					<el-radio-group v-model="form.degree">
						<el-radio :label="431">非常紧急</el-radio>
						<el-radio :label="432">急</el-radio>
						<el-radio :label="433">普通</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="处理结果:" prop="aresult">
					<el-radio-group v-model="form.aresult">
						<el-radio :label="416">未处理</el-radio>
						<el-radio :label="417">处理中</el-radio>
						<el-radio :label="418">处理完成</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="处理过程：">
					<el-input type="textarea" :autosize="{ minRows: 2, maxRows: 2}" v-model="form.progress"></el-input>
				</el-form-item>

				<el-form-item label="客户反馈：">
					<el-input type="textarea" :autosize="{ minRows: 2, maxRows: 2}" v-model="form.feedback"></el-input>
				</el-form-item>
				
			
			<el-form-item>
				<el-col :span="8"></el-col>
				<el-col :span="8">
					<el-button @click="resetForm('form')">重置</el-button>
					<el-button type="primary" @click="submitForm('form')">立即创建</el-button>
				</el-col>
				<el-col :span="8"></el-col>
			</el-form-item>
		</el-form>
		</div>

		<script>
			var vms = new Vue({
				el: "#app",
				data() {
					return {
						customertoman: [],
						pickerOptions1: { //时间做约束
							disabledDate(time) {
								return time.getTime() > Date.now() - 8.64e6;
							}
						},
						form: {
							theme: '',
							user: '',
							type: '',
							date1: '',
							custname: '',
							custid: '',
							degree: '',
							progress: '',
							aresult: '',
							spendtime: '',
							feedback: '',
							custback: '',
							linkman: '',
							linid: '',
							more: '',
							id: '',
							restaurants: []

						},
						//验证规则
						rules: { //数据源model
							theme: [{
								required: true,
								message: '请输入主题',
								trigger: 'blur'
							}, ],
							user: [{
								required: true,
								message: '请选择执行人',
								trigger: 'blur'
							}],
							type: [{
								required: true,
								message: '请选择投诉类型',
								trigger: 'blur'
							}],
							custname: [{
								required: true,
								message: '请选择客户',
								trigger: 'blur'
							}],
							linkman: [{
								required: true,
								message: '请选择投诉人',
								trigger: 'blur'
							}],
							degree: [{
								required: true,
								message: '请选择程度',
								trigger: 'blur'
							}],
							aresult: [{
								required: true,
								message: '请选择处理结果',
								trigger: 'blur'
							}],
							date1: [{
								required: true,
								message: '请选择时间',
								trigger: 'blur'
							}],
							feedback: [{
								required: true,
								message: '请输入客户反馈内容',
								trigger: 'blur'
							}]
						
						}
					}
				},
				methods: {
					submitForm(formName) {
						//验证方法
						this.$refs[formName].validate((valid) => {
							if(valid) {

								var par = null;

								if(JSON.stringify(${
										tousu
									}) === '{}') {
									par = "/tousuform";

								} else {
									par = "/editertousuform";

									this.form.id = ${
										tousu.com_id
									} + "";
								}
								//post提交数据
								axios.post(par,
									//参数转换
									Qs.stringify(this.form, {
										arrayFormat: 'brackets'
									})
									//	params:
									//ajax请求成功的回调函数
								).then(function(v) {
								if(v.data == true){
										window.parent.location.href="/getTousuty";
									}else{
										window.parent.parent.location.href = "/getErrorty";
									}
								}).catch(function() {
									alert("出错了");
								});

							} else {
								console.log('error submit!!');
								return false;
							}
						});
					},
					resetForm(formName) {
						this.$refs[formName].resetFields();
					},

					resetForm(formName) {
						this.$refs[formName].resetFields();
					},
					//queryString实时的文本框的值,cb回调函数
					querySearch: function(queryString, cb) {
						var allarr = this.form.restaurants;
						// console.info(allarr);

						var newsarr = [];
						allarr.forEach(v => {
							var strs = v.cus_name + "";
							if(strs.indexOf(queryString) >= 0) {
								newsarr.push(v);
								console.info(strs);
								console.info(v);
							}
						})
						// 调用 callback 返回建议列表的数据
						cb(newsarr);
					},
					handleSelect: function(it) {
						console.log(it.cus_name);
						//alert(it.cus_id);
						this.form.custname = it.cus_name;
						this.form.custid = it.cus_id;

						var iosnn = this;

						//post提交数据
						axios.post("/onSale/findByCoustomerName",
							//参数转换
							Qs.stringify(this.form, {
								arrayFormat: 'brackets'
							})
						).then(function(v) {
							iosnn.customertoman = v.data.custo;
							console.info(v.data);
						}).catch(function(e) {
							alert("出错了" + e);
						});
					},
					handleSelect1: function(it) {
						//	alert("ss");
						this.form.linid = it;
					},
				},
				mounted() {
					var dic = ${
						dictionaryitem
					};
					//console.log(dic); 
					var mas = ${
						mansitem
					};
					this.form.restaurants = mas;
					//console.log(this.form.restaurants); 

					var news = ${
						tousu
					};
					console.log(news);

					this.form.theme = news.com_name;
					this.form.type = news.com_classify;
					this.form.dates = news.com_date;
					this.form.custname = news.cus_name;
					this.form.custid = news.cus_id;
					this.form.degree = news.com_degree;
					this.form.progress = news.com_treati;
					this.form.aresult = news.com_result;
					this.form.spendtime = news.com_spendtime;
					this.form.feedback = news.com_feedback;
					this.form.linkman = news.lin_name;
					this.form.linid = news.com_complaint;
					this.form.date1 = news.finishtime;

				}
			});
		</script>
	</body>

</html>